package com.skzh.web.controller.equipment;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.skzh.common.core.domain.model.LoginUser;
import com.skzh.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.skzh.common.annotation.Log;
import io.swagger.annotations.ApiOperation;
import com.skzh.common.core.controller.BaseController;
import com.skzh.common.core.domain.AjaxResult;
import com.skzh.common.enums.BusinessType;
import com.skzh.equipment.domain.LightControl;
import com.skzh.equipment.service.ILightControlService;
import com.skzh.common.utils.poi.ExcelUtil;
import com.skzh.common.core.page.TableDataInfo;

/**
 * 灯光控制配置Controller
 *
 * @author skzh
 * @date 2025-03-22
 */
@RestController
@RequestMapping("/system/control")
public class LightControlController extends BaseController {
    @Autowired
    private ILightControlService lightControlService;

    /**
     * 查询灯光控制配置列表
     */
    @ApiOperation(value = "查询灯光控制配置列表")
    @PreAuthorize("@ss.hasPermi('system:control:list')")
    @GetMapping("/list" )
    public TableDataInfo list(LightControl lightControl) {
        startPage();
        List<LightControl> list = lightControlService.selectLightControlList(lightControl);
        return getDataTable(list);
    }

    /**
     * 导出灯光控制配置列表
     */
    @ApiOperation(value = "导出灯光控制配置列表")
    @PreAuthorize("@ss.hasPermi('system:control:export')" )
    @Log(title = "灯光控制配置" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, LightControl lightControl) {
        List<LightControl> list = lightControlService.selectLightControlList(lightControl);
        ExcelUtil<LightControl> util = new ExcelUtil<LightControl>(LightControl. class);
        util.exportExcel(response, list, "灯光控制配置数据" );
    }

    /**
     * 获取灯光控制配置详细信息
     */
    @ApiOperation(value = "获取灯光控制配置详细信息")
    @PreAuthorize("@ss.hasPermi('system:control:query')" )
    @GetMapping(value = "/{lcId}" )
    public AjaxResult getInfo(@PathVariable("lcId" ) Long lcId) {
        return success(lightControlService.selectLightControlByLcId(lcId));
    }

    /**
     * 新增灯光控制配置
     */
    @ApiOperation(value = "新增灯光控制配置")
    @PreAuthorize("@ss.hasPermi('system:control:add')" )
    @Log(title = "灯光控制配置" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LightControl lightControl) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        lightControl.setCreateBy(loginUser.getUsername());
        return toAjax(lightControlService.insertLightControl(lightControl));
    }

    /**
     * 修改灯光控制配置
     */
    @ApiOperation(value = "修改灯光控制配置")
    @PreAuthorize("@ss.hasPermi('system:control:edit')" )
    @Log(title = "灯光控制配置" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LightControl lightControl) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        lightControl.setUpdateBy(loginUser.getUsername());
        return toAjax(lightControlService.updateLightControl(lightControl));
    }

    /**
     * 删除灯光控制配置
     */
    @ApiOperation(value = "删除灯光控制配置")
    @PreAuthorize("@ss.hasPermi('system:control:remove')" )
    @Log(title = "灯光控制配置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{lcIds}" )
    public AjaxResult remove(@PathVariable Long[] lcIds) {
        return toAjax(lightControlService.deleteLightControlByLcIds(lcIds));
    }
}
